// pages/orderinfo/orderinfo.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    gid: '',
    coupon: [],
    index: 0,
    goods:[],
    newprice:[]
  },
  radioChange(e) {
    let cid = e.detail.value
    let price=this.data.goods.price
    let that=this
    wx.request({
      url: 'http://fbj.wdmnm.vip/api/couponInfo',
      data:{
        cid:cid
      },
      success:function(res){
        if(res.data.code==200){
          console.log()
          that.setData({
            newprice:(res.data.data[0].coupon_price)-(price)
          })
          
        }
      }
    })
  },
  formSubmit(e) {
    let address = e.detail.value.address
    let gid = this.data.gid
    let uid = wx.getStorageSync('uid')
    wx.request({
      url: 'http://fbj.wdmnm.vip/api/createOrder',
      data: {
        address: address,
        gid: gid,
        uid: uid
      },
      method: "POST",
      success: function (res) {
        if (res.data.code == 200) {
          wx.navigateTo({
            url: '/pages/paychoice/paychoice?id=' + res.data.data,
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let gid = options.gid
    let that = this
    let uid = wx.getStorageSync('uid')
    that.setData({
      gid: gid
    })
    wx.request({
      url: 'http://fbj.wdmnm.vip/api/userCoupon',
      data: {
        uid: uid
      },
      success: function (res) {
        if (res.data.code == 200) {
          that.setData({
            coupon: res.data.data
          })
        }
      }
    })
    wx.request({
      url: 'http://fbj.wdmnm.vip/api/goodsInfo',
      data:{
        gid:gid
      },
      success:function(res){
        if(res.data.code==200){
          that.setData({
            goods:res.data.data
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})